package main

import (
  "bytes"
  "fmt"
  "log"
  "os"
  "os/exec"
  "time"
)

//运行命令的
var (
  cmd *exec.Cmd
)

func Kill() {
  log.Println("test cmd")
  if cmd != nil && cmd.Process != nil {
    log.Println(cmd.Process.Pid)
    err := cmd.Process.Kill()
    if err != nil {
      log.Fatal(err)
    }
  }
}

func Start(out *bytes.Buffer, started chan bool) {

  cmdString3 := "tk.exe"
  cmd := exec.Command(cmdString3)

  cmd.Stdout = out
  //cmd.Stdout = os.Stdout
  cmd.Stderr = os.Stderr
  //    err := cmd.Run()
  //    if err != nil {
  //      log.Fatal(err)
  //    }

  go cmd.Run()


  // out1,err := cmd.CombinedOutput()
  // if err != nil{
  //   log.Fatal(err)
  // }

  // fmt.Println("out",out1)
  started <- true
}

func main() {

  var started = make(chan bool)
  var out bytes.Buffer

  go Start(&out, started)

  <-time.After(time.Second * 3)
  Kill()

  fmt.Println(<-started)

  fmt.Printf("in all caps: %q\n", out.String())
}